From 853dda39e76582cb4c971c878913e89b85ce0dfc Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Fri, 23 Dec 2011 10:48:57 -0500 Subject: [PATCH] ostbuild: Move autodiscover-meta to ostbuild executor --- Makefile-ostbuild.am | 2 +- src/ostbuild/ostbuild-autodiscover-meta | 81 ----------------- .../pyostbuild/builtin_autodiscover_meta.py | 91 +++++++++++++++++++ src/ostbuild/pyostbuild/main.py | 1 + 4 files changed, 93 insertions(+), 82 deletions(-) delete mode 100755 src/ostbuild/ostbuild-autodiscover-meta create mode 100755 src/ostbuild/pyostbuild/builtin_autodiscover_meta.py diff --git a/Makefile-ostbuild.am b/Makefile-ostbuild.am index 07588606..96b2e376 100644 --- a/Makefile-ostbuild.am +++ b/Makefile-ostbuild.am @@ -20,7 +20,6 @@ ostbuild: src/ostbuild/ostbuild.in Makefile bin_SCRIPTS += ostbuild bin_SCRIPTS += \ - src/ostbuild/ostbuild-autodiscover-meta \ src/ostbuild/ostbuild-commit-artifacts \ src/ostbuild/ostbuild-chroot-compile-one-impl \ src/ostbuild/ostbuild-nice-and-log-output \ @@ -34,6 +33,7 @@ pyostbuild_PYTHON = \ src/ostbuild/pyostbuild/ostbuildlog.py \ src/ostbuild/pyostbuild/subprocess_helpers.py \ src/ostbuild/pyostbuild/builtin_compile_one.py \ + src/ostbuild/pyostbuild/builtin_autodiscover_meta.py \ $(NULL) bin_PROGRAMS += src/ostbuild/ostbuild-user-chroot diff --git a/src/ostbuild/ostbuild-autodiscover-meta b/src/ostbuild/ostbuild-autodiscover-meta deleted file mode 100755 index 15f2311c..00000000 --- a/src/ostbuild/ostbuild-autodiscover-meta +++ /dev/null @@ -1,81 +0,0 @@ -#!/usr/bin/python -# -# Copyright (C) 2011 Colin Walters -# -# This library is free software; you can redistribute it and/or -# modify it under the terms of the GNU Lesser General Public -# License as published by the Free Software Foundation; either -# version 2 of the License, or (at your option) any later version. -# -# This library is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# Lesser General Public License for more details. -# -# You should have received a copy of the GNU Lesser General Public -# License along with this library; if not, write to the -# Free Software Foundation, Inc., 59 Temple Place - Suite 330, -# Boston, MA 02111-1307, USA. - -import os,sys,re,subprocess,tempfile,shutil -import argparse - -parser = argparse.ArgumentParser(description="Discover source metadata from current directory") -parser.add_argument('--meta') - -args = parser.parse_args() - -AUTODISCOVERED_KEYS = {} -KEYS = {} - -def _register_discover_func(key, func): - if key not in AUTODISCOVERED_KEYS: - AUTODISCOVERED_KEYS[key] = [] - AUTODISCOVERED_KEYS[key].append(func) - -def _discover_name_from_cwd(): - return os.path.basename(os.getcwd()) -_register_discover_func('NAME', _discover_name_from_cwd) - -def _discover_version_from_git(): - if os.path.isdir('.git'): - try: - version = subprocess.check_output(['git', 'describe']) - except subprocess.CalledProcessError, e: - version = subprocess.check_output(['git', 'rev-parse', 'HEAD']) - return version.strip() - return None -_register_discover_func('VERSION', _discover_version_from_git) - -def _discover_branch_from_git(): - if os.path.isdir('.git'): - try: - ref = subprocess.check_output(['git', 'symbolic-ref', 'HEAD']) - return ref.replace('refs/heads/', '').strip() - except subprocess.CalledProcessError, e: - return None - return None -_register_discover_func('BRANCH', _discover_branch_from_git) - -if args.meta: - f = open(args.meta) - for line in f.readlines(): - (k,v) = line.split('=', 1) - KEYS[k.strip()] = v.strip() - f.close() - -for (key,hooks) in AUTODISCOVERED_KEYS.iteritems(): - if key in KEYS: - continue - for func in hooks: - value = func() - - if value is None: - continue - - KEYS[key] = value - break - -for (key,value) in KEYS.iteritems(): - print "%s=%s" % (key, value) - diff --git a/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py b/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py new file mode 100755 index 00000000..68080248 --- /dev/null +++ b/src/ostbuild/pyostbuild/builtin_autodiscover_meta.py @@ -0,0 +1,91 @@ +#!/usr/bin/python +# +# Copyright (C) 2011 Colin Walters +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with this library; if not, write to the +# Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +import os,sys,re,subprocess,tempfile,shutil +import argparse + +from . import builtins +from .ostbuildlog import log, fatal + +class OstbuildAutodiscoverMeta(builtins.Builtin): + name = "autodiscover-meta" + short_description = "Extract metadata from the current source directory" + + def execute(self, argv): + parser = argparse.ArgumentParser(self.short_description) + parser.add_argument('--meta') + + args = parser.parse_args(argv) + + KEYS = {} + AUTODISCOVERED_KEYS = {} + + def _register_discover_func(key, func): + if key not in AUTODISCOVERED_KEYS: + AUTODISCOVERED_KEYS[key] = [] + AUTODISCOVERED_KEYS[key].append(func) + + _register_discover_func('NAME', self._discover_name_from_cwd) + _register_discover_func('VERSION', self._discover_version_from_git) + _register_discover_func('BRANCH', self._discover_branch_from_git) + + if args.meta: + f = open(args.meta) + for line in f.readlines(): + (k,v) = line.split('=', 1) + KEYS[k.strip()] = v.strip() + f.close() + + for (key,hooks) in AUTODISCOVERED_KEYS.iteritems(): + if key in KEYS: + continue + for func in hooks: + value = func() + + if value is None: + continue + + KEYS[key] = value + break + + for (key,value) in KEYS.iteritems(): + print "%s=%s" % (key, value) + + def _discover_name_from_cwd(self): + return os.path.basename(os.getcwd()) + + def _discover_version_from_git(self): + if os.path.isdir('.git'): + try: + version = subprocess.check_output(['git', 'describe']) + except subprocess.CalledProcessError, e: + version = subprocess.check_output(['git', 'rev-parse', 'HEAD']) + return version.strip() + return None + + def _discover_branch_from_git(self): + if os.path.isdir('.git'): + try: + ref = subprocess.check_output(['git', 'symbolic-ref', 'HEAD']) + return ref.replace('refs/heads/', '').strip() + except subprocess.CalledProcessError, e: + return None + return None + +builtins.register(OstbuildAutodiscoverMeta) diff --git a/src/ostbuild/pyostbuild/main.py b/src/ostbuild/pyostbuild/main.py index 916f6da0..5cd5587e 100755 --- a/src/ostbuild/pyostbuild/main.py +++ b/src/ostbuild/pyostbuild/main.py @@ -23,6 +23,7 @@ import argparse from . import builtins from . import builtin_compile_one +from . import builtin_autodiscover_meta def usage(ecode): print "Builtins:" -- 2.30.2